const redisCli = require('../dbs/redisCli').client;
const createToken = require('./createToken');
const setCookie = require('./setCookie');
const checkToken = require('./checkToken');
module.exports = async (ctx,next) => {
    let token = ctx.cookies.get('token');
    if (token) {
        let username = ctx.session[token];
        if (username && checkToken(username)) {
            //更新token
            console.log('更新token')
            const token_new = createToken(username);
            setCookie(ctx,'token',token_new);
            ctx.session[token_new] = username;
            return true;
        }else{
            return false;
        }
    }else{
        return false;
    }
}